<?php

/**
 * 产品相关接口
 */
class a_product extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->url = $this->uri->segments;
    }

    /**
     * 产品列表分页
     * @param int $configid 网站id
     * @param int $classid 产品分类
     * @param int $isrecommend 是否推荐 1 推荐 ，2未推荐 0 所有
     * @param int $page 当前页数
     * @param int $limit 显示数量
     * @return array 
     */
    function get_product_list_page($configid = 0, $classid = 0, $isrecommend = 0, $page = 1, $limit = 10) {
        $where = array(
            'product.isclose' => 0
        );
        if ($configid > 0) {
            $where['class.configid'] = $configid;
        }
        if ($classid > 0) {
            $where['product.classid'] = $classid;
        }
        if ($isrecommend == 1) {
            $where['product.isrecommend'] = 1;
        } elseif ($isrecommend == 2) {
            $where['product.isrecommend'] = 0;
        }

        $data = array(
            'from' => 'product',
            'column' => 'product.productid,product.classid,product.productname,product.smallpic,product.description,class.classname',
            'join' => array(
                'class' => 'class.classid=product.classid',
            ),
            'where' => $where,
            'order' => 'product.listid desc',
        );

        $result = $this->m_public->get_list_page($data, $page, $limit);
        return $result;
    }
    
     /**
     * 产品列表
     * @param int $configid 网站id
     * @param int $classid 产品分类
     * @param int $isrecommend 是否推荐 1 推荐 ，2未推荐 0 所有
     * @param int $limit 显示数量
     * @return array 
     */
    function get_product_list($configid = 0, $classid = 0, $isrecommend = 0,$limit = 10) {
        $where = array(
            'product.isclose' => 0
        );
        if ($configid > 0) {
            $where['class.configid'] = $configid;
        }
        if ($classid > 0) {
            $where['product.classid'] = $classid;
        }
        if ($isrecommend == 1) {
            $where['product.isrecommend'] = 1;
        } elseif ($isrecommend == 2) {
            $where['product.isrecommend'] = 0;
        }

        $data = array(
            'from' => 'product',
            'column' => 'product.productid,product.classid,product.productname,product.smallpic,product.description,class.classname',
            'join' => array(
                'class' => 'class.classid=product.classid',
            ),
            'where' => $where,
            'order' => 'product.listid desc',
            'offset' =>0,
            'limit'=>$limit,
        );

        $result = $this->m_public->get_list($data);
        return $result;
    }

    /**
     * 产品图片列表
     * @param int $productid
     * @param int $limit
     * @return array
     */
    function get_productpic_list($productid, $limit = 10) {
        $where = array(
            'productpic.isclose' => 0,
            'productpic.productid' => $productid,
        );

        $data = array(
            'from' => 'productpic',
            'where' => $where,
            'order' => 'productpic.listid desc',
            'offset' => 0,
            'limit' => $limit,
        );
        return $this->m_public->get_list($data);
    }

    /**
     * 产品图片列表 分页
     * @param int $productid
     * @param int $page
     * @param int $limit
     * @return array
     */
    function get_productpic_list_page($productid, $page = 1, $limit = 10) {
        $where = array(
            'productpic.isclose' => 0,
            'productpic.productid' => $productid,
        );
        
        $data = array(
            'from' => 'productpic',
            'where' => $where,
            'order' => 'productpic.listid desc',
        );
        return $this->m_public->get_list_page($data, $page, $limit);
    }
    
    /**
     * 获取产品
     * @param int $productid
     * @return array
     */
    function get_product($productid) {
        $data = array(
            'productid' => $productid,
        );
        return $this->m_public->getRowInfo('product', $data);
    }
    /**
     * 获取产品图片
     * @param int $productpicid
     * @return array
     */
    function get_productpic($productpicid) {
        $data = array(
            'productpicid' => $productpicid,
        );
        return $this->m_public->getRowInfo('productpic', $data);
    }

}
